/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-06-22
 * Time: 23:27
 */
class Animal {
    public void eat() {

    }
}
class Dog extends Animal {
    @Override
    public void eat() {
        System.out.println("狗在吃饭");
    }
    public void swim() {
        System.out.println("狗在游泳");
    }
}
public class Test2 {
    public static void main(String[] args) {
        Animal animal = new Dog();
        if(animal instanceof Dog dog) {//判断animal引用的是否为Dog类
            dog.swim();
        }
    }
    public static void main1(String[] args) {
        Animal animal = new Dog();
        if(animal instanceof Dog) {//判断animal引用的是否为Dog类
            Dog dog = (Dog)animal;
            dog.swim();
        }
    }
}
